#ifndef _P2P_ENGINE_H_
#define _P2P_ENGINE_H_

#include "sock_utils.h"
#include "p2p-file.h"
#include "p2p-config.h"
#include "p2p-peer.h"

typedef struct {
    int state;
    int peer_sockfd;
} state_t;

typedef uint8_t block_map_t[NO_OF_BLOCKS]; 

int handle_msg(int sockfd, char *recv_buf, int bytes_recvd, peer_list_t *peer_list);
int init();
int connect_to_peers(const socket_t *local_socket, const socket_t *remote_socket, 
                     fd_set *master, int *fdmax, int remote_socket_count, peer_list_t *peer_list);
int send_handshake_to_peers(peer_list_t *peer_list);
int check_missing_piece();
int cleanup(peer_list_t *peer_list, int sockfd);
int request_block(int sockfd, peer_t *peer, block_t *block, int no_of_pieces);

#endif // ifndef _P2P_ENGINE_H_ 
